package com.xunk.system.service.impl;

import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.xunk.common.core.domain.UploadFile;
import com.xunk.system.domain.SysBimModel;
import com.xunk.system.mapper.SysBimModelMapper;
import com.xunk.system.service.ISysBimModelService;
import com.xunk.system.service.UploadFileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 模型Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-10
 */
@Service
public class SysBimModelServiceImpl implements ISysBimModelService
{

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SysBimModelMapper sysBimModelMapper;

    @Autowired
    private FastFileStorageClient storageClient;

    @Autowired
    private UploadFileService uploadFileService;

    /**
     * 查询模型
     * 
     * @param modelId 模型ID
     * @return 模型
     */
    @Override
    public SysBimModel selectSysBimModelById(Long modelId)
    {
        return sysBimModelMapper.selectSysBimModelById(modelId);
    }

    /**
     * 查询模型列表
     * 
     * @param sysBimModel 模型
     * @return 模型
     */
    @Override
    public List<SysBimModel> selectSysBimModelList(SysBimModel sysBimModel)
    {
        return sysBimModelMapper.selectSysBimModelList(sysBimModel);
    }

    /**
     * 新增模型
     * 
     * @param sysBimModel 模型
     * @return 结果
     */
    @Override
    public int insertSysBimModel(SysBimModel sysBimModel)
    {
        return sysBimModelMapper.insertSysBimModel(sysBimModel);
    }

    /**
     * 修改模型
     * 
     * @param sysBimModel 模型
     * @return 结果
     */
    @Override
    public int updateSysBimModel(SysBimModel sysBimModel)
    {
        return sysBimModelMapper.updateSysBimModel(sysBimModel);
    }

    /**
     * 批量删除模型
     * 
     * @param modelIds 需要删除的模型ID
     * @return 结果
     */
    @Override
    public int deleteSysBimModelByIds(Long[] modelIds)
    {
        return sysBimModelMapper.deleteSysBimModelByIds(modelIds);
    }

    /**
     * 删除模型信息
     * 
     * @param modelId 模型ID
     * @return 结果
     */
    @Override
    public int deleteSysBimModelById(Long modelId)
    {
        return sysBimModelMapper.deleteSysBimModelById(modelId);
    }

    @Override
    public UploadFile uploadModelFile(MultipartFile file) throws IOException {
        return uploadFileService.uploadFile(file);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int bindModelAndDept(Long modelId, Long[] deptIds) {
        for (Long deptId : deptIds) {
            sysBimModelMapper.updateSysHome(modelId,deptId);
        }
        return 0;
    }
}
